package cn.ibizlab.odoo.core.odoo_survey.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Isurvey_user_input;
import cn.ibizlab.odoo.core.odoo_survey.domain.Survey_user_input;
import cn.ibizlab.odoo.core.odoo_survey.filter.Survey_user_inputSearchContext;
import cn.ibizlab.odoo.core.odoo_survey.service.ISurvey_user_inputService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[调查用户输入] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Survey_user_inputServiceImpl implements ISurvey_user_inputService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Isurvey_user_inputClientService survey_user_inputClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //survey_user_inputClientService.removeBatch(survey_user_inputs) ;

    }

    @Override
    public boolean update(Survey_user_input survey_user_input) {
        boolean bOk = false ;
        Isurvey_user_input clientModel = this.convert2Model(survey_user_input,null);
        survey_user_inputClientService.update(clientModel) ;
        this.convert2Domain(clientModel,survey_user_input) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean create(Survey_user_input survey_user_input) {
        boolean bOk = false ;
        Isurvey_user_input clientModel = this.convert2Model(survey_user_input,null);
        survey_user_inputClientService.create(clientModel) ;
        this.convert2Domain(clientModel,survey_user_input);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Isurvey_user_input clientModel = survey_user_inputClientService.createModel();
        clientModel.setId(id);
        survey_user_inputClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Survey_user_input> survey_user_inputs, int batchSize) {

                        //survey_user_inputClientService.createBatch(survey_user_inputs,batchSize) ;

    }

    @Override
    public void updateBatch(List<Survey_user_input> survey_user_inputs, int batchSize) {

        //survey_user_inputClientService.updateBatch(survey_user_inputs,batchSize) ;

    }

    @Override
    public Survey_user_input get(Integer id) {
        Isurvey_user_input clientModel = survey_user_inputClientService.createModel();
        clientModel.setId(id);
        survey_user_inputClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Survey_user_input get(Survey_user_input survey_user_input) {
        Survey_user_input retsurvey_user_input = this.get(survey_user_input.getId()) ;
    	BeanCopier copier=BeanCopier.create(retsurvey_user_input.getClass(), survey_user_input.getClass(), false);
        copier.copy(retsurvey_user_input, survey_user_input, null);
        return survey_user_input ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Survey_user_input> searchDefault(Survey_user_inputSearchContext context) {
        List<Survey_user_input> list = new ArrayList<Survey_user_input>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input> clientModelList = survey_user_inputClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据联系人查询
     */
    @Override
    public Page<Survey_user_input> selectByOdoo_partner(Integer id){
        Survey_user_inputSearchContext context = new Survey_user_inputSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input> list = new ArrayList<Survey_user_input>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input> clientModelList = survey_user_inputClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Survey_user_input> selectByOdoo_create(Integer id){
        Survey_user_inputSearchContext context = new Survey_user_inputSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input> list = new ArrayList<Survey_user_input>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input> clientModelList = survey_user_inputClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Survey_user_input> selectByOdoo_write(Integer id){
        Survey_user_inputSearchContext context = new Survey_user_inputSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input> list = new ArrayList<Survey_user_input>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input> clientModelList = survey_user_inputClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据问卷页面查询
     */
    @Override
    public Page<Survey_user_input> selectByOdoo_last_displayed_page(Integer id){
        Survey_user_inputSearchContext context = new Survey_user_inputSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input> list = new ArrayList<Survey_user_input>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input> clientModelList = survey_user_inputClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据问卷查询
     */
    @Override
    public Page<Survey_user_input> selectByOdoo_survey(Integer id){
        Survey_user_inputSearchContext context = new Survey_user_inputSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_user_input> list = new ArrayList<Survey_user_input>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_user_input> clientModelList = survey_user_inputClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_user_input clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_user_input>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Isurvey_user_input convert2Model(Survey_user_input domain , Isurvey_user_input model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = survey_user_inputClientService.createModel() ;
        }

         if(domain.getUser_input_line_idsDirtyFlag())
            model.setUser_input_line_ids(domain.getUser_input_line_ids());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getQuizz_scoreDirtyFlag())
            model.setQuizz_score(domain.getQuizz_score());
         if(domain.getTokenDirtyFlag())
            model.setToken(domain.getToken());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getEmailDirtyFlag())
            model.setEmail(domain.getEmail());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getTest_entryDirtyFlag())
            model.setTest_entry(domain.getTest_entry());
         if(domain.getDeadlineDirtyFlag())
            model.setDeadline(domain.getDeadline());
         if(domain.getTypeDirtyFlag())
            model.setType(domain.getType());
         if(domain.getDate_createDirtyFlag())
            model.setDate_create(domain.getDate_create());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getPrint_urlDirtyFlag())
            model.setPrint_url(domain.getPrint_url());
         if(domain.getResult_urlDirtyFlag())
            model.setResult_url(domain.getResult_url());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getSurvey_idDirtyFlag())
            model.setSurvey_id(domain.getSurvey_id());
         if(domain.getLast_displayed_page_idDirtyFlag())
            model.setLast_displayed_page_id(domain.getLast_displayed_page_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Survey_user_input convert2Domain( Isurvey_user_input model ,Survey_user_input domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Survey_user_input();
        }

        if(model.getUser_input_line_idsDirtyFlag())
            domain.setUser_input_line_ids(model.getUser_input_line_ids());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getQuizz_scoreDirtyFlag())
            domain.setQuizz_score(model.getQuizz_score());
        if(model.getTokenDirtyFlag())
            domain.setToken(model.getToken());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getEmailDirtyFlag())
            domain.setEmail(model.getEmail());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getTest_entryDirtyFlag())
            domain.setTest_entry(model.getTest_entry());
        if(model.getDeadlineDirtyFlag())
            domain.setDeadline(model.getDeadline());
        if(model.getTypeDirtyFlag())
            domain.setType(model.getType());
        if(model.getDate_createDirtyFlag())
            domain.setDate_create(model.getDate_create());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getPrint_urlDirtyFlag())
            domain.setPrint_url(model.getPrint_url());
        if(model.getResult_urlDirtyFlag())
            domain.setResult_url(model.getResult_url());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getSurvey_idDirtyFlag())
            domain.setSurvey_id(model.getSurvey_id());
        if(model.getLast_displayed_page_idDirtyFlag())
            domain.setLast_displayed_page_id(model.getLast_displayed_page_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
